package com.eastfair.messagecenter.util;

import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.messagecenter.dto.SmsSendDTO;
import com.eastfair.messagecenter.enumeration.ChannelType;
import com.eastfair.messagecenter.model.SmsContentModel;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class SmsSendDtoUtil {
    /**
     * 内容属性名称
     */
    private String mapName = "content";

    /**
     * 发送短信 组装实体
     *
     * @param bysinessType
     * @param mobiles
     * @param content
     * @return
     */
    public static SmsSendDTO sendSmsDto(String bysinessType, Set<String> mobiles, String content) {
        SmsSendDTO smsSendDTO = new SmsSendDTO();
        smsSendDTO.setBusinessType(bysinessType);
        smsSendDTO.setChannelType(ChannelType.SMS);
        smsSendDTO.setBusinessId(ContextUtil.getTrace());
        smsSendDTO.setMobileList(mobiles);
        SmsContentModel smsContentModel = new SmsContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        smsContentModel.setContentMap(contentMap);
        smsSendDTO.setSmsContentModelList(Arrays.asList(smsContentModel));
        return smsSendDTO;
    }


    /**
     * 发送短信 组装实体
     *
     * @param bysinessType
     * @param mobiles
     * @param content
     * @return
     */
    public static SmsSendDTO sendSmsDto(String bysinessType, Set<String> mobiles, String content, LocalDateTime predictSendTime) {
        SmsSendDTO smsSendDTO = new SmsSendDTO();
        smsSendDTO.setBusinessType(bysinessType);
        smsSendDTO.setChannelType(ChannelType.SMS);
        smsSendDTO.setBusinessId(ContextUtil.getTrace());
        smsSendDTO.setMobileList(mobiles);
        SmsContentModel smsContentModel = new SmsContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        smsContentModel.setContentMap(contentMap);
        smsSendDTO.setSmsContentModelList(Arrays.asList(smsContentModel));
        if (predictSendTime == null) {
            smsSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            smsSendDTO.setPredictSendTime(predictSendTime);
            smsSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return smsSendDTO;
    }


    /**
     * 发送短信 组装实体
     *
     * @param bysinessType
     * @param userIds
     * @param content
     * @return
     */
    public static SmsSendDTO sendSmsDtoOfUserId(String bysinessType, Set<Long> userIds, String content, LocalDateTime predictSendTime) {
        SmsSendDTO smsSendDTO = new SmsSendDTO();
        smsSendDTO.setBusinessType(bysinessType);
        smsSendDTO.setChannelType(ChannelType.SMS);
        smsSendDTO.setBusinessId(ContextUtil.getTrace());
        smsSendDTO.setSenUserIdList(userIds);
        SmsContentModel smsContentModel = new SmsContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        smsContentModel.setContentMap(contentMap);
        smsSendDTO.setSmsContentModelList(Arrays.asList(smsContentModel));
        if (predictSendTime == null) {
            smsSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            smsSendDTO.setPredictSendTime(predictSendTime);
            smsSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return smsSendDTO;
    }


    /**
     * 发送短信 组装实体
     *
     * @param bysinessType
     * @param orgIds
     * @param content
     * @return
     */
    public static SmsSendDTO sendSmsDtoOfOrgId(String bysinessType, Set<Long> orgIds, String content, LocalDateTime predictSendTime) {
        SmsSendDTO smsSendDTO = new SmsSendDTO();
        smsSendDTO.setBusinessType(bysinessType);
        smsSendDTO.setChannelType(ChannelType.SMS);
        smsSendDTO.setBusinessId(ContextUtil.getTrace());
        smsSendDTO.setOrgIdList(orgIds);
        SmsContentModel smsContentModel = new SmsContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        smsContentModel.setContentMap(contentMap);
        smsSendDTO.setSmsContentModelList(Arrays.asList(smsContentModel));
        if (predictSendTime == null) {
            smsSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            smsSendDTO.setPredictSendTime(predictSendTime);
            smsSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return smsSendDTO;
    }


    /**
     * 发送短信 组装实体
     *
     * @param bysinessType
     * @param isSendAll
     * @param content
     * @return
     */
    public static SmsSendDTO sendSmsDtoOfOrgId(String bysinessType, Boolean isSendAll, String content, LocalDateTime predictSendTime) {
        SmsSendDTO smsSendDTO = new SmsSendDTO();
        smsSendDTO.setBusinessType(bysinessType);
        smsSendDTO.setChannelType(ChannelType.SMS);
        smsSendDTO.setBusinessId(ContextUtil.getTrace());
        smsSendDTO.setIsSendAll(isSendAll);
        SmsContentModel smsContentModel = new SmsContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        smsContentModel.setContentMap(contentMap);
        smsSendDTO.setSmsContentModelList(Arrays.asList(smsContentModel));
        if (predictSendTime == null) {
            smsSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            smsSendDTO.setPredictSendTime(predictSendTime);
            smsSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return smsSendDTO;
    }

}
